<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>浏览器对象模型</title>
	</head>
	<body>
		<a href="#" onclick="goOther()">跳转</a>
		<a href="#" onclick="closeOther()">关闭</a>
		<a href="#" onclick="buy()">我要买东西</a>
		<a href="#" onclick="start()">开始计时</a>
		<a href="#" onclick="stop()">暂停计时</a>
		<a href="#" onclick="restart()">重置计时</a>
		<a href="#" onclick="end()">结束计时</a>
	</body>
	<script>
		let seconds = 0
		let myInterval = undefined
		function start(){
			if(myInterval === undefined){
				myInterval = setInterval(function(){
					console.log("当前的时间为：" + ++seconds + "秒")
				},1000)
			}
		}
		
		function stop(){
			if(myInterval !== undefined){
				clearInterval(myInterval)
				console.log("您暂停了计时，当前时间为：" + seconds+ "秒")
				myInterval = undefined
			}
			
		}
		
		function restart(){
			if(myInterval !== undefined){
				console.log("您重置了时间，当前时间为：" + seconds+ "秒")
				seconds = 0
			
			}
			
		}
		
		function end(){
			if(myInterval !== undefined){
				clearInterval(myInterval)
				console.log("您结束了计时，结束时间为：" + seconds+ "秒")
				myInterval = undefined
				seconds = 0
			}
			
		}
		
		let otherWindow
		function goOther(){
			otherWindow = window.open('./index2.html','index2',"width=800,height=600")//打开窗口地址为参数一，描述为参数三
		}
		function closeOther(){
//			try{
//				otherWindow.close()
//			}catch{
//				console.log('无已打开网页')
//			}
			if(otherWindow!==undefined && !otherWindow.isClosed){
				otherWindow.close()
			}
				
		}
		function buy(){
			let name = window.prompt("Hello,what's your name:")
			window.alert('welcome' + name + '!')
			let thing = window.prompt("What thing do you want to buy?")
			let nums = window.prompt("What the number of it?")
			window.alert("")
		}
//		window.onload = function(){
//			let time = 5
//			let i = 1
//			setTimeout(function(){
//				document.writeln("已经过去了" + time + "秒")
//			}, time * 1000)
//			var myIntrval = setInterval(function(){
//				console.log(i++)
//			},1000)
//			setTimeout(function(){
//				clearInterval(myIntrval)
//			}, 5000)
//		}
	</script>
</html>
